package main

import (
	"dnsmap/dns"
	"fmt"
	"github.com/urfave/cli"
	"os"
	"runtime"
	"runtime/debug"
)

var (
	app *cli.App
)

func init() {
	app = cli.NewApp()
	app.Name = "dnsmap"
	app.Usage = "Subdomain discovery"
	app.Authors = []cli.Author{
		{Name: "Dean", Email: "dean@csoio.com"},
	}
	app.Version = "1.0.1"
	app.Copyright = "dnsmap.csoio.com"
	app.Description = "Dnsmap is a high-performance subdomain discovery tool built with golang."
	debug.SetMaxThreads(200000)
	runtime.GOMAXPROCS(runtime.NumCPU())
}

func main() {

	app.Flags = []cli.Flag{

		cli.StringFlag{
			Name:  "domain, d",
			Usage: "domain",
		},

		cli.IntFlag{
			Name:  "concurrency, c",
			Value: 30,
			Usage: "Concurrent quantity, reasonably allocated according to current machine performance",
		},

		cli.IntFlag{
			Name:  "timeout, t",
			Value: 10,
			Usage: "Request timeout",
		},

		cli.StringFlag{
			Name:  "wordlist, w",
			Usage: "Wordlist file to use for enumeration.",
			Value: "resources/names.txt",
		},

		cli.StringFlag{
			Name:  "output, o",
			Usage: "Save the result to a file",
			Value: "results.csv",
		},

		cli.BoolFlag{
			Name:  "debug",
			Usage: "Enable debug mode",
		},
	}

	app.Action = func(c *cli.Context) error {
		return dns.New(c)
	}

	if err := app.Run(os.Args); err != nil {
		fmt.Println(err)
	}

}
